import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';

import 'package:get/get.dart';
import 'package:zrjz/comm/constants/api_constants.dart';
import 'package:zrjz/comm/constants/color_constants.dart';
import 'package:zrjz/comm/constants/constants.dart';
import 'package:zrjz/comm/utils/ex_widget.dart';
import 'package:zrjz/comm/widget/global_web/global_web_page.dart';
import 'package:zrjz/comm/widget/my_load_image.dart';
import 'package:zrjz/comm/widget/my_text_view.dart';
import 'package:zrjz/generated/assets.dart';

/// 应用启动同意协议的弹窗，同意之后才能进入App
class PrivacyPolicyDialog extends StatelessWidget {
  VoidCallback? cancelAction;
  VoidCallback? confirmAction;
  String? cancemText;
  String? confirmText;

  PrivacyPolicyDialog({
    super.key,
    this.cancemText,
    this.cancelAction,
    this.confirmText,
    this.confirmAction,
  });

  @override
  Widget build(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.center,
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        //Title
        Container(
          decoration:  BoxDecoration(
            color: DarkThemeUtil.multiColors(ColorConstants.appBlue,darkColor: ColorConstants.darkBlackItemLight) ,
            borderRadius: const BorderRadius.only(
              topLeft: Radius.circular(5),
              topRight: Radius.circular(5),
            ),
          ),
          padding: const EdgeInsets.only(left: 30, right: 10, top: 5, bottom: 5),
          child: Row(
            children: [
              Expanded(
                child: MyTextView(
                  "隐私保护政策".tr,
                  fontSize: 18,
                  marginTop: 15,
                  marginBottom: 16,
                  isFontMedium: true,
                  textColor: ColorConstants.whitefe,
                  textAlign: TextAlign.center,
                ),
              ),
            ],
          ),
        ),

        Container(
          width: double.infinity,
          decoration:  BoxDecoration(
            color: DarkThemeUtil.multiColors(ColorConstants.white,darkColor: ColorConstants.darkBlackItemLightMost),
            borderRadius: const BorderRadius.only(
              bottomLeft: Radius.circular(5),
              bottomRight: Radius.circular(5),
            ),
          ),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              //code
              MyTextView(
                '欢迎来到Room!'.tr,
                fontSize: 14,
                textColor: DarkThemeUtil.multiColors(ColorConstants.black,darkColor: ColorConstants.white),
                isFontBold: true,
                textAlign: TextAlign.center,
                marginLeft: 18.5,
                marginRight: 18.5,
                marginTop: 26,
                marginBottom: 24,
              ),

              RichText(
                  text: TextSpan(
                text: '我们将通过',
                style:  TextStyle(fontSize: 13, color: DarkThemeUtil.multiColors(ColorConstants.black,darkColor:
                ColorConstants.white), fontWeight: FontWeight.w500),
                children: <TextSpan>[
                  TextSpan(
                    text: '《Room用户协议》',
                    style:  const TextStyle(
                      color:  ColorConstants.appBlue,
                      fontSize: 13,
                      fontWeight: FontWeight.w500,
                    ),
                    recognizer: TapGestureRecognizer()
                      ..onTap = () {
                        GlobalWebPage.startInstance("用户协议与条款", ApiConstants.userAgreementUrl);
                      },
                  ),
                  const TextSpan(text: '和'),
                  TextSpan(
                    text: '《隐私政策》',
                    style:  const TextStyle(
                      color: ColorConstants.appBlue,
                      fontWeight: FontWeight.w500,
                      fontSize: 13,
                    ),
                    recognizer: TapGestureRecognizer()
                      ..onTap = () {
                        GlobalWebPage.startInstance("隐私协议", ApiConstants.privacyPolicyUrl);
                      },
                  ),
                  const TextSpan(text: '帮助您了解我们为您提供的服务，及收集、处理您个人信息的方式。点击「同意并继续」按钮代表您已同意'),
                ],
              )).marginOnly(left: 29, right: 29, bottom: 24),
              //Buttons
              Column(
                children: [
                  MyTextView(
                    confirmText ?? "同意并继续".tr,
                    marginLeft: 18.5,
                    paddingTop: 10,
                    paddingBottom: 10,
                    fontSize: 16,
                    isFontMedium: true,
                    marginRight: 18.5,
                    textAlign: TextAlign.center,
                    textColor: ColorConstants.white,
                    backgroundColor: ColorConstants.blue1578fe,
                    cornerRadius: 3,
                    onClick: () {
                      onCancel();
                      confirmAction?.call();
                    },
                  ).constrained(width: double.infinity),

                  MyTextView(
                    cancemText ?? "不同意，去浏览模式".tr,
                    marginLeft: 18.5,
                    marginRight: 18.5,
                    marginTop: 10,
                    paddingTop: 10,
                    paddingBottom: 10,
                    fontSize: 14,
                    isFontMedium: true,
                    textAlign: TextAlign.center,
                    textColor: ColorConstants.white,
                    backgroundColor: ColorConstants.blue1578fe,
                    cornerRadius: 3,
                    onClick: () {
                      onCancel();
                      cancelAction?.call();
                    },
                  ).constrained(width: double.infinity),

                  MyTextView(
                    cancemText ?? "不同意，退出应用".tr,
                    marginLeft: 18.5,
                    marginRight: 18.5,
                    marginTop: 10,
                    marginBottom: 24,
                    paddingTop: 10,
                    paddingBottom: 10,
                    textAlign: TextAlign.center,
                    fontSize: 14,
                    isFontMedium: true,
                    textColor: DarkThemeUtil.multiColors(ColorConstants.blue1578fe,darkColor: ColorConstants.white),
                    borderColor: ColorConstants.blue1578fe,
                    cornerRadius: 3,
                    onClick: () {
                      onCancel();
                      // 点击按钮时，调用 SystemNavigator.pop() 方法退出应用
                      SystemNavigator.pop();
                    },
                  ).constrained(width: double.infinity),

                ],
              ),
            ],
          ),
        ),
      ],
    ).constrained(width: 295);
  }

  //取消弹框
  void onCancel() async {
    SmartDialog.dismiss();
  }
}
